import React, { Component } from 'react';
import { Card, Modal, message, Radio, Row, Col, Form, Input, Button,  } from 'antd';
import { connect } from 'dva'
import { trim as trimReg } from "@/utils/regexp";
import { exitWindowOpen } from "@/utils/index"
import styles from './styles.less';

const FormItem = Form.Item;
const RadioGroup = Radio.Group;
const { TextArea } = Input;
let checkCode = {
  'BL003': 'submitCompanyApplyCheckForm',
  'BL004': 'submitCompanyApplyCheckForm',
  'BL005': 'submitIdentityCheckForm',
}
@Form.create()
@connect(({ loading }) => ({
  loading: loading.effects['todoDetail/submitCompanyApplyCheckForm'],
}))
class AuditResults extends Component {

  handleSubmit = e => {
    e.preventDefault();
    const { serialNo, form, dispatch, history, code } = this.props;
    form.validateFieldsAndScroll((err, values) => {
      if (!err) {

        dispatch({
          type: `todoDetail/${checkCode[code]}`,
          payload: {
            id:serialNo,
            ...values,
          },
        })
          .then(msg => {
            message.success("提交成功！");
            setTimeout(()=>{
              exitWindowOpen();
            },2000)
          })
          .catch(errMsg => {
            message.error(errMsg);
          });
      }
    });
  };

  render() {
    const {
      headStyle,
      form: { getFieldDecorator },
      loading,
      code,
    } = this.props;
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 2 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 },
      },
    };
    const processStateOptions = [
      { label: '通过', value: '1' },
      { label: '驳回', value: '2' },
    ];
    return (
      <Card
          title="审核结果"
          headStyle={headStyle}
          style={{ marginBottom: '20px' }}
        >
        <Form onSubmit={this.handleSubmit}>
          <Row>
            <Col span={24}>
              <FormItem {...formItemLayout} label="审核结果">
                {getFieldDecorator(code === 'BL005' ? 'auditStatus' : 'processState', {
                  //initialValue: companyInformation.name,
                  rules: [
                    {
                      required: true,
                      message: '请选择审核结果',
                    },
                  ],
                })(<RadioGroup options={processStateOptions} />)}
              </FormItem>
            </Col>
          </Row>
          <Row>
            <Col span={24}>
              <FormItem {...formItemLayout} label="审核说明">
                {getFieldDecorator(code === 'BL005' ? 'auditRemark' : 'processRemark', {
                    rules: [
                      {
                        //required: true,
                        message: '请输入备注',
                        pattern: trimReg,
                      },
                      {
                        max: 255,
                        message: '255个字符以内',
                      },
                    ],
                  })(
                    <TextArea
                      rows={4}
                      placeholder="请输入备注" />
                  )}
              </FormItem>
            </Col>
          </Row>
          <Row>
            <Col span={2} >

            </Col>
            <Col span={18} >
              <Button type="primary" htmlType="submit" disabled={loading}>
                {loading ? '请稍后' : '提交'}
              </Button>
            </Col>
          </Row>
        </Form>
    </Card>
    );
  }
}

export default AuditResults;
